# Maintainer: Daniel Bermond <dbermond@archlinux.org>
# Maintainer: Bruno Pagani <archange@archlinux.org>

_pkg=py-lmdb
pkgname=python-lmdb
pkgver=1.4.1
pkgrel=2
pkgdesc="Universal Python binding for the LMDB Lightning Database"
arch=(loong64 x86_64)
url="https://github.com/jnwatson/py-lmdb/"
license=('custom: OpenLDAP')
depends=(python python-cffi lmdb)
makedepends=(python-build python-installer python-setuptools python-wheel)
checkdepends=(python-pytest)
source=(${url}/archive/${_pkg}_${pkgver}.tar.gz)
sha256sums=('c574035dd85ef7f5b1d6d9c9f639fcaff51fcf85a397c5b6d721e161e6077f51')

build() {
  cd ${_pkg}-${_pkg}_${pkgver}
  LMDB_FORCE_SYSTEM=1 python -m build --wheel --no-isolation
}

check() {
  cd ${_pkg}-${_pkg}_${pkgver}
  local _pyver
  _pyver="$(python -c 'import sys; print("".join(map(str, sys.version_info[:2])))')"
  LMDB_FORCE_SYSTEM=1 PYTHONPATH="${PWD}"/build/lib.linux-$CARCH-cpython-${_pyver} pytest -vv --color=yes
}

package() {
  cd ${_pkg}-${_pkg}_${pkgver}
  local _pyver
  _pyver="$(python -c 'import sys; print("%s.%s" %sys.version_info[0:2])')"
  LMDB_FORCE_SYSTEM=1 python -m installer --destdir="$pkgdir" dist/*.whl
  install -d -m755 "${pkgdir}"/usr/share/licenses/${pkgname}
  ln -s ../../../lib/python${_pyver}/site-packages/lmdb-${pkgver}.dist-info/LICENSE \
    "${pkgdir}"/usr/share/licenses/${pkgname}/LICENSE
}
